package com.jy.adscm.hcPlan.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.jy.adscm.exception.AdscmSystemException;
import com.jy.adscm.hcPlan.bean.*;
import com.jy.adscm.hcPlan.bean.support.BaseSupport;
import com.jy.adscm.hcPlan.bean.support.HcPlanMakePartMaterielExampleSupport;
import com.jy.adscm.hcPlan.bean.support.HcPlanMaterielExportPrintSupport;
import com.jy.adscm.hcPlan.bean.support.MaterielBaseSupport;
import com.jy.adscm.hcPlan.mapper.mysql.*;
import com.jy.adscm.hcPlan.service.HcPlanMakePartMaterielExampleService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.jy.adscm.utils.AdscmBaseUtils;
import com.jy.adscm.utils.AdscmDateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * <p>
 * 单批次零件制造对应的物料需求 服务实现类
 * </p>
 *
 * @author yyy
 * @since 2018-08-23
 */
@Service
public class HcPlanMakePartMaterielExampleServiceImpl extends ServiceImpl<HcPlanMakePartMaterielExampleMapper, HcPlanMakePartMaterielExample> implements HcPlanMakePartMaterielExampleService {

    Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    HcPlanMakePartExampleMapper hcPlanMakePartExampleMapper;
    @Autowired
    HcPlanFinalAssemblyMapper hcPlanFinalAssemblyMapper;
    @Autowired
    HcPlanMakePartMapper hcPlanMakePartMapper;
    @Autowired
    HcPlanSaleMapper hcPlanSaleMapper;
    @Autowired
    HcPlanMakePartMaterielMapper hcPlanMakePartMaterielMapper;
    @Autowired
    Hc_plan_materielMapper hc_plan_materielMapper;
    @Autowired
    HcPlanMakePartMaterielExampleMapper hcPlanMakePartMaterielExampleMapper;
    @Autowired
    Hc_plan_materiel_other_config_exampleMapper hc_plan_materiel_other_config_exampleMapper;
    @Autowired
    Hc_plan_supplierMapper hc_plan_supplierMapper;
    @Autowired
    HcPlanBaseCommodityinfoMapper baseCommodityinfoMapper;
    @Autowired
    HcPlanBaseTaskinfoMapper baseTaskinfoMapper;


//    @Transactional
    @Override
    public void loadHcPartMaterielExampleByAssemblyId(Long assemblyId) throws AdscmSystemException {
        logger.info("装配单批次零件制造的对应的物料需求数据，总装id【"+assemblyId+"】...");

        try{

            Wrapper<HcPlanMakePartMaterielExample> pm_wrapper = new EntityWrapper<>();
            pm_wrapper.eq("assembly_id",assemblyId);
            Integer pmCount = hcPlanMakePartMaterielExampleMapper.selectCount(pm_wrapper);
            if (pmCount != null && pmCount > 0){
                return;
            }


            HcPlanFinalAssembly assembly = hcPlanFinalAssemblyMapper.selectById(assemblyId);
            if (AdscmBaseUtils.getInstance().isNotEmpty(assembly,"id")){


                HcPlanSale planSale = hcPlanSaleMapper.getPlanSale(assembly.getSale_task_flow_num(), assembly.getGoods_id());

                //--------------------------------------------------------------------------------------------------

                Date materielArrived_time = null;

                Wrapper<HcPlanMakePartExample> wrapper = new EntityWrapper<>();
                wrapper.eq("assembly_id",assemblyId);
                //一个总装对应的单批次耗材零件制造配置
                List<HcPlanMakePartExample> partExamples = hcPlanMakePartExampleMapper.selectList(wrapper);


                String goods_type = null;

                //对以上所有的零件，生成相关的物料需求
                if (partExamples != null && partExamples.size()>0){
                    for (HcPlanMakePartExample example :
                            partExamples) {
                        HcPlanMakePartMaterielExample pme = new HcPlanMakePartMaterielExample();
                        pme.setSale_task_flow_num(assembly.getSale_task_flow_num());
                        pme.setCustomer_msg(planSale.getCustomer_msg());
                        pme.setGoods_id(planSale.getGoods_id());
                        pme.setGoods_name(planSale.getGoods_name());
                        pme.setGoods_model(planSale.getGoods_model());
                        pme.setGoods_type(example.getGoods_type());
                        if (goods_type == null){
                            goods_type = example.getGoods_type();
                        }
                        pme.setPlan_arrived_time(planSale.getPlan_arrived_time());
                        pme.setAssembly_id(assemblyId);
                        pme.setAss_start_date(assembly.getAss_start_date());
                        pme.setAss_end_date(assembly.getAss_end_date());

                        pme.setPart_id(example.getPart_id());
                        pme.setPart_name(example.getPart_name());
                        pme.setPart_merge_id(example.getMerge_id());
                        pme.setMake_start_time(example.getMake_start_time());
                        pme.setMake_end_time(example.getMake_end_time());

                        HcPlanMakePart part = hcPlanMakePartMapper.selectById(example.getPart_id());//零件
//                        HcPlanMakePartMateriel materiel = hcPlanMakePartMaterielMapper.selectById(part.getMake_materiel_id());//物料
                        Hc_plan_materiel materiel = hc_plan_materielMapper.selectById(part.getMake_materiel_id());//物料

                        pme.setMake_materiel_id(part.getMake_materiel_id());
                        pme.setMake_materiel_name(part.getMake_materiel_name());
                        pme.setMateriel_type(materiel.getUse_type());

                        pme.setPart_materiel_status(0);

                        if(pme.getGoods_type().startsWith("A")){
                            pme.setPart_make_total_num(part.getA_materiel_batch_kg());
                        }else {
                            pme.setPart_make_total_num(part.getG_materiel_batch_kg());
                        }

                        hcPlanMakePartMaterielExampleMapper.insert(pme);
                    }
                }

                Wrapper<Hc_plan_materiel> wrapper1 = new EntityWrapper<>();
                wrapper1.where("use_type != '零件制造物料' ",new Object[0]);
//                List<HcPlanMakePartMateriel> partMateriels = hcPlanMakePartMaterielMapper.selectList(wrapper1);
                List<Hc_plan_materiel> p_materiels = hc_plan_materielMapper.selectList(wrapper1);

                if(p_materiels != null && p_materiels.size()>0){
                    for (Hc_plan_materiel materiel :
                            p_materiels) {

                        HcPlanMakePartMaterielExample pme = new HcPlanMakePartMaterielExample();
                        pme.setSale_task_flow_num(assembly.getSale_task_flow_num());
                        pme.setCustomer_msg(planSale.getCustomer_msg());
                        pme.setGoods_id(planSale.getGoods_id());
                        pme.setGoods_name(planSale.getGoods_name());
                        pme.setGoods_model(planSale.getGoods_model());
                        pme.setGoods_type(goods_type);
                        pme.setPlan_arrived_time(planSale.getPlan_arrived_time());
                        pme.setAssembly_id(assemblyId);
                        pme.setAss_start_date(assembly.getAss_start_date());
                        pme.setAss_end_date(assembly.getAss_end_date());

                        pme.setMake_materiel_id(materiel.getId());
                        pme.setMake_materiel_name(materiel.getMateriel_name());
                        pme.setMateriel_type(materiel.getUse_type());

                        pme.setPart_materiel_status(0);

                        hcPlanMakePartMaterielExampleMapper.insert(pme);

                    }
                }

                //--------------------------------------------------------------------------------------

            }

        }catch (Exception e){
            logger.error("装配单批次零件制造的对应的物料需求数据，总装id【"+assemblyId+"】异常",e);
            throw new AdscmSystemException(e.getMessage());
        }

    }

    @Override
    public List<Map<String, Object>> getAllMakePartMaterielExample() throws AdscmSystemException {
        List<Map<String, Object>> list = null;
        logger.info("获取所有正在进行中的零件制造对应的物料需求记录...");
        try {
            List<HcPlanMakePartMaterielExampleSupport> materielExample = hcPlanMakePartMaterielExampleMapper.getAllFinalPartMaterielExample();

            if (materielExample != null && materielExample.size()>0){

                list = new ArrayList<>();

                for (HcPlanMakePartMaterielExampleSupport example : materielExample){
                    Map<String, Object> map = new HashMap<>();
                    Map<String, Object> data = new HashMap<>();

                    Map<String, Object> counts = new HashMap<>();
                    Map<String, Object> ljzzwl = new HashMap<>();
                    Map<String, Object> ljzzwl_content = new HashMap<>();
                    ljzzwl.put("name","零件制造物料");
                    ljzzwl.put("partsValue",0);
                    ljzzwl.put("value",0);
                    ljzzwl.put("content",ljzzwl_content);


                    counts.put("ljzzwl",ljzzwl);

                    counts.put("zpwl",new MaterielBaseSupport("装配物料",0,0,new HashMap<>()));//new BaseSupport("包装物料",0));
                    counts.put("dbwl",new MaterielBaseSupport("打包物料",0,0,new HashMap<>()));//new BaseSupport("检验物料",0));//
                    counts.put("qxwl",new MaterielBaseSupport("清洗物料",0,0,new HashMap<>()));//new BaseSupport("清洗物料",0));
                    counts.put("mjwl",new MaterielBaseSupport("灭菌物料",0,0,new HashMap<>()));//new BaseSupport("灭菌物料",0));

                    map.put("counts",counts);
                    map.put("data",data);

                    data.put("sale_task_flow_num",example.getSale_task_flow_num());
                    data.put("customer_msg",example.getCustomer_msg());
                    data.put("goods_id",example.getGoods_id());
                    data.put("goods_name",example.getGoods_name());
                    data.put("goods_model",example.getGoods_model());
                    data.put("plan_arrived_time",example.getPlan_arrived_time());
                    data.put("assembly_id",example.getAssembly_id());
                    data.put("ass_start_date",example.getAss_start_date());
                    data.put("ass_end_date",example.getAss_end_date());


                    List<HcPlanMakePartMaterielExample> materiels = example.getMaterielList();


                    Map<String, Object> materiel_temp = new HashMap<>();

                    if (materiels != null && materiels.size()>0){
                        for(HcPlanMakePartMaterielExample materiel : materiels){



                            switch (materiel.getMateriel_type()){
                                case "零件制造物料":
                                    Integer partsValue = (Integer) ljzzwl.get("partsValue");
                                    ljzzwl.put("partsValue",partsValue + 1);

//                                    data.put("part"+(partsValue + 1),materiel);

//                                    ljzzwl_content.put("materiel"+(partsValue + 1),new BaseSupport("灭菌物料",0));

                                    Integer mmId = materiel.getMake_materiel_id();
                                    Object obj = materiel_temp.get("part"+mmId);
                                    Map<String,Object> cMap = null;
                                    if (obj == null){
                                        cMap = new HashMap<>();
                                        materiel_temp.put("part"+mmId,cMap);
                                    }else {
                                        cMap = (Map<String,Object>)obj;
                                    }
//                                    materiel.setParent_tag("part"+mmId);
                                    cMap.put("materiel"+materiel.getPart_id(),materiel);
//                                    materiel_temp.put("part"+map.get("ljzzwl"),materiel);
                                    break;
                                case "装配物料":
                                    MaterielBaseSupport zpwl = (MaterielBaseSupport) counts.get("zpwl");
                                    int zpwl_count = zpwl.getValue();
                                    zpwl.setValue(zpwl_count + 1);
                                    zpwl.setPartsValue(zpwl.getValue());
                                    Map<String, BaseSupport> zp_content = zpwl.getContent();
                                    zp_content.put("material"+zpwl.getValue(),new BaseSupport(materiel.getMake_materiel_name(),1));
                                    data.put("zpwl"+zpwl.getValue(),materiel);
                                    break;
                                case "打包物料":
                                    MaterielBaseSupport dbwl = (MaterielBaseSupport) counts.get("dbwl");
                                    int dbwl_count = dbwl.getValue();
                                    dbwl.setValue(dbwl_count + 1);
                                    dbwl.setPartsValue(dbwl.getValue());
                                    Map<String, BaseSupport> db_content = dbwl.getContent();
                                    db_content.put("material"+dbwl.getValue(),new BaseSupport(materiel.getMake_materiel_name(),1));
                                    data.put("dbwl"+dbwl.getValue(),materiel);
                                    break;
                                case "清洗物料":
                                    MaterielBaseSupport qxwl = (MaterielBaseSupport) counts.get("qxwl");
                                    int qxwl_count = qxwl.getValue();
                                    qxwl.setValue(qxwl_count + 1);
                                    qxwl.setPartsValue(qxwl.getValue());
                                    Map<String, BaseSupport> qx_content = qxwl.getContent();
                                    qx_content.put("material"+qxwl.getValue(),new BaseSupport(materiel.getMake_materiel_name(),1));
                                    data.put("qxwl"+qxwl.getValue(),materiel);
                                    break;
                                case "灭菌物料":
                                    MaterielBaseSupport mjwl = (MaterielBaseSupport) counts.get("mjwl");
                                    int mjwl_count = mjwl.getValue();
                                    mjwl.setValue(mjwl_count + 1);
                                    mjwl.setPartsValue(mjwl.getValue());
                                    Map<String, BaseSupport> mj_content = mjwl.getContent();
                                    mj_content.put("material"+mjwl.getValue(),new BaseSupport(materiel.getMake_materiel_name(),1));
                                    data.put("mjwl"+mjwl.getValue(),materiel);
                                    break;

                            }

                        }

                        Set<String> keys = materiel_temp.keySet();
                        if (keys != null){
                            ljzzwl.put("value",keys.size());
                        }
//                        ljzzwl_content
                        Iterator<String> it = keys.iterator();
                        int i = 1;
                        int j = 1;
//                        Map<String ,Object> partMap = new HashMap<>();
                        while (it.hasNext()){
                            String key = it.next();
                            Object value = materiel_temp.get(key);

                            Map<String,Object> cMap = (Map<String,Object>)value;
                            if (cMap != null){
                                Set<String> mKeys = cMap.keySet();
                                if (mKeys != null && mKeys.size()>0){
                                    Iterator<String> tempIt = mKeys.iterator();
                                    HcPlanMakePartMaterielExample m_temp = (HcPlanMakePartMaterielExample)cMap.get(tempIt.next());
                                    ljzzwl_content.put("material"+ i++ , new BaseSupport(m_temp.getMake_materiel_name(),mKeys.size()));

                                    data.put("part"+(j++),m_temp);
                                    while (tempIt.hasNext()){
                                        data.put("part"+(j++),(HcPlanMakePartMaterielExample)cMap.get(tempIt.next()));
                                    }
                                }
                            }

//                            partMap.put("part"+i++,value);
                        }
//                        map.putAll(partMap);

                    }

                    list.add(map);

                }
            }




        }catch (Exception e){
            logger.error("获取所有正在进行中的零件制造对应的物料需求记录异常",e);
            throw new AdscmSystemException(e.getMessage());
        }
        return list;
    }

    @Transactional
    @Override
    public String mergePartMateriel(String materiel_purchase_time,String materiel_arrived_time,String payment_date,Double materiel_total_price,Double materiel_total_kg,String supplier_id, String isUpdate, List<Long> ids) throws AdscmSystemException {
        logger.info("开始进行物料采购并单【"+ids+"】...");
        try {
            String mergeId = null;
            Integer merge_sort_num = null;
            if (!"1".equals(isUpdate)){
                mergeId = AdscmDateUtils.getNowOnlyDateFomat2(new Date());
                merge_sort_num = hcPlanMakePartMaterielExampleMapper.getMaxMergeSortNum(mergeId);
                if (merge_sort_num == null){
                    merge_sort_num = 1;
                }else {
                    merge_sort_num += 1;
                }
                String result = AdscmBaseUtils.getInstance().addZeroToStr(merge_sort_num.toString(),3,"0");
                mergeId += result;
            }


            if (ids != null && ids.size()>0){
                List<HcPlanMakePartMaterielExample> materielExamples = hcPlanMakePartMaterielExampleMapper.selectBatchIds(ids);
                Hc_plan_supplier supplier = hc_plan_supplierMapper.selectById(supplier_id);
                if (materielExamples != null && materielExamples.size()>0){
                    for (HcPlanMakePartMaterielExample materiel:
                            materielExamples) {

                        if (!"1".equals(isUpdate)){
                            materiel.setMerge_puchase_id(mergeId);
                            materiel.setMerge_sort_num(merge_sort_num);
                        }else {
                            if (mergeId == null){
                                mergeId = materiel.getMerge_puchase_id();
                            }
                        }
//                        String supplierName = hcPlanMakePartMaterielExampleMapper.getSupplierById(supplier_id);
                        if (supplier != null){
                            materiel.setSupplier_id(supplier_id);//供应商
                            materiel.setSupplier_name(supplier.getSupplier_name());
                        }
                        materiel.setMateriel_purchase_time(AdscmDateUtils.parseDate(materiel_purchase_time));
                        materiel.setMateriel_arrived_time(AdscmDateUtils.parseDate(materiel_arrived_time));

                        materiel.setMateriel_total_price(materiel_total_price);
                        materiel.setMateriel_total_num(materiel_total_kg);

                        materiel.setPayment_date(AdscmDateUtils.parseDate(payment_date));

                        materiel.setPart_materiel_status(1);

                        hcPlanMakePartMaterielExampleMapper.updateById(materiel);
                    }


                }else {
                    throw new AdscmSystemException("没有查询到【"+ids+"】需要并单的零件物料集合，物料采购并单失败");
                }

            }else {
                throw new AdscmSystemException("没有获取到需要并单的零件物料集合，物料采购并单失败");
            }

            return mergeId;
        }catch (Exception e){
            logger.error("物料采购并单【"+ids+"】异常",e);
            throw new AdscmSystemException(e.getMessage());
        }
    }

    @Override
    public List<Map<String, Object>> getAllSupplier() throws AdscmSystemException {
        logger.info("获取所有物料供应商...");
        return hcPlanMakePartMaterielExampleMapper.getAllSupplier();
    }


    @Override
    public Map<String, Object> calculatePurchaseMaterielTime(Long[] ids) throws AdscmSystemException {

        logger.info("程序自动计算，选择的一物料的采购时间、采购数量、供应商...");
        Map<String, Object> map = new HashMap<>();
        try {
            //获取所有选择的物料详情
            if (ids != null && ids.length > 0){
                List<HcPlanMakePartMaterielExample> materielExamples = hcPlanMakePartMaterielExampleMapper.selectBatchIds(Arrays.asList(ids));



                if (materielExamples != null && materielExamples.size()>0){
                    HcPlanMakePartMaterielExample temp = materielExamples.get(0);

                    Hc_plan_materiel materiel = hc_plan_materielMapper.selectById(temp.getMake_materiel_id());//物料
                    //获取物料标准配置中的那几个环节（检验、清洗、生产准备、到货周期）的时间
                    Integer inspection_cycle = materiel.getInspection_cycle();
                    Integer cleaning_cycle = materiel.getCleaning_cycle();
                    Integer stock_up_cycle = materiel.getStock_up_cycle();
                    Integer transport_cycle = materiel.getTransport_cycle();

                    map.put("inspection_cycle",inspection_cycle);
                    map.put("cleaning_cycle",cleaning_cycle);
                    map.put("stock_up_cycle",stock_up_cycle);
                    map.put("transport_cycle",transport_cycle);

                    //获取物料的供应商
                    List<Hc_plan_supplier> suplier = hc_plan_supplierMapper.getSuplierByMaterielId(temp.getMake_materiel_id());
                    map.put("suplier",suplier);

                    //物料采购最早的开始时间
                    Date minMaterielDate = null;
                    Double materiel_total_kg = 0d;//物料总需求重量

                    //如果是零件制造物料
                    if ("零件制造物料".equals(temp.getMateriel_type())){
                        //循环整个 materielExamples ，取得所有零件制造物料的数量


                        for (HcPlanMakePartMaterielExample me :
                                materielExamples) {
                            HcPlanMakePart part = hcPlanMakePartMapper.selectById(me.getPart_id());//零件
                            if (me.getGoods_type().startsWith("A")){
                                materiel_total_kg += part.getA_materiel_batch_kg();
                            }else {
                                materiel_total_kg += part.getG_materiel_batch_kg();
                            }

                            if (minMaterielDate == null){
                                minMaterielDate = me.getMake_start_time();
                            }else {
                                if (me.getMake_start_time().getTime() < minMaterielDate.getTime()){
                                    minMaterielDate = me.getMake_start_time();
                                }
                            }

                        }


                    }else {
                        //其他物料
                        //循环整个 materielExamples ，取得所有其他物料的标准配置
                        for (HcPlanMakePartMaterielExample me :
                                materielExamples) {
                            Hc_plan_materiel hpm = hc_plan_materielMapper.selectById(me.getMake_materiel_id());//物料
                            if (me.getGoods_type().startsWith("A")){
                                materiel_total_kg += hpm.getA_batch_num();
                            }else {
                                materiel_total_kg += hpm.getG_batch_num();
                            }

                            //最早时间就是最早的总装的开始时间
                            if (minMaterielDate == null){
                                minMaterielDate = me.getAss_start_date();
                            }else {
                                if (minMaterielDate.getTime() > me.getAss_start_date().getTime()){
                                    minMaterielDate = me.getAss_start_date();
                                }
                            }

                        }


                    }
                    map.put("materiel_total_kg",materiel_total_kg);
                    Float unit_price = materiel.getUnit_price();//单价
                    Double materiel_total_price = materiel_total_kg * unit_price;//物料总需求价格

                    map.put("materiel_total_price",materiel_total_price);

                    Date materiel_arrived_time = null;//采购到货时间
                    Date materiel_purchase_time = null;//开始采购时间

                    //物料采购的到货时间就应该是 minMaterielDate - 生产准备期 - 清洗周期 - 检验周期
                    materiel_arrived_time = AdscmDateUtils.getThatDate(minMaterielDate,AdscmBaseUtils.getInstance().getOppositeNum(inspection_cycle + cleaning_cycle + stock_up_cycle),Calendar.DATE);

                    //采购开始时间应该是 materiel_arrived_time - 到货周期
                    materiel_purchase_time = AdscmDateUtils.getThatDate(materiel_arrived_time,AdscmBaseUtils.getInstance().getOppositeNum(transport_cycle),Calendar.DATE);

                    map.put("materiel_arrived_time",materiel_arrived_time);
                    map.put("materiel_purchase_time",materiel_purchase_time);

                }



            }else {
                throw new AdscmSystemException("没有获取到 ids 参数");
            }


        }catch (Exception e){
            logger.error("程序自动计算，选择的一批物料的采购时间、采购数量、供应商异常",e);
            throw new AdscmSystemException(e.getMessage());
        }

        return map;
    }


    @Transactional
    @Override
    public void submitMaterielTask(String merge_id) throws AdscmSystemException {

        logger.info("开始发布物料采购任务，并单id：【"+merge_id+"】");
        try {
            //修改任务下发状态
            Wrapper<HcPlanMakePartMaterielExample> wrapper = new EntityWrapper<>();
            wrapper.eq("merge_puchase_id",merge_id);
            List<HcPlanMakePartMaterielExample> materielExamples = hcPlanMakePartMaterielExampleMapper.selectList(wrapper);

            if (materielExamples != null && materielExamples.size()>0){

                HcPlanMakePartMaterielExample temp = null;
                for (HcPlanMakePartMaterielExample example :
                        materielExamples) {

                    if (temp == null){
                        temp = example;
                    }

                    example.setPart_materiel_status(2);
                    hcPlanMakePartMaterielExampleMapper.updateById(example);
                }

                Hc_plan_supplier supplier = hc_plan_supplierMapper.selectById(temp.getSupplier_id());
                Hc_plan_materiel hc_plan_materiel = hc_plan_materielMapper.selectById(temp.getMake_materiel_id());

                //下发采购任务
                BaseTaskinfo taskinfo = new BaseTaskinfo();
                BaseCommodityinfo info = new BaseCommodityinfo();

                taskinfo.setTid(UUID.randomUUID().toString());
                Date now = new Date();
                taskinfo.setTcode(Long.parseLong(new SimpleDateFormat("yyyyMMddHHmmssms").format(now)));
                taskinfo.setFbsj(now);
                taskinfo.setRwlx(1);
                taskinfo.setKhxx(supplier.getSupplier_code() == null ? supplier.getSupplier_name() : supplier.getSupplier_code());//客户信息
                taskinfo.setBzry("07b5ab9b-f1c4-4750-b4cf-4d790e90350b");//翠华
                taskinfo.setFzry("f6d52fbf-40f6-475e-80cf-732461ba6459");//罗茜
                taskinfo.setHwzt(0);
                taskinfo.setHkzt(0);
                taskinfo.setFpzt(0);
                taskinfo.setRwzt(0);
                taskinfo.setRwwczt(0);
                taskinfo.setIsproviderstockup(0);
                taskinfo.setIscheckupgoods(0);
                taskinfo.setOrdernums(new SimpleDateFormat("yyyyMMddHHmmssms").format(now));//订单号
                taskinfo.setGoodsname(hc_plan_materiel.getMateriel_name());//商品名称
                taskinfo.setSum(temp.getMateriel_total_price());//商品总金额

                info.setSpid(UUID.randomUUID().toString());
                info.setSpmc(taskinfo.getGoodsname());//商品名称
                info.setSpxh(hc_plan_materiel.getMateriel_spec());//商品型号
                info.setSpjhsl(temp.getMateriel_total_num().intValue());//商品计划数量
                info.setSpjhdj(hc_plan_materiel.getUnit_price().doubleValue());//商品计划单价
                info.setSpjhzj(temp.getMateriel_total_price());//商品计划总价
                info.setTid(taskinfo.getTid());
                info.setSptjsj(now);//商品添加时间，要修改
                info.setSpjhsfsj(temp.getPayment_date());//商品计划付款时间，要修改
                info.setTotal(temp.getMateriel_total_num());//
                info.setSjtotal(1d);//
                info.setPlanarrivedtime(temp.getMateriel_arrived_time());//计划到货时间
                info.setCommodityuse("1");//商品类型：1，表示耗材生产

                baseTaskinfoMapper.insert(taskinfo);
                baseCommodityinfoMapper.insert(info);

            }else{
                throw new AdscmSystemException("并单ID【"+merge_id+"】无效，无法提交任务");
            }

        }catch (Exception e){
            logger.error("发布物料采购任务"+merge_id,e);
            throw new AdscmSystemException(e.getMessage());
        }
    }

    @Override
    public List<HcPlanMaterielExportPrintSupport> getAllMaterielExprotPrintMsg(String date) throws AdscmSystemException {

        logger.info("开始获取【"+date+"】的采购计划...");

        return hcPlanMakePartMaterielExampleMapper.getAllMaterielExprotPrintMsg(date);
    }
}
